package com.kl.controller;


import com.kl.em.ConstantEnum;
import com.kl.em.Result;
import com.kl.entity.Role;
import com.kl.service.IRoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private IRoleService iRoleService;


    @ApiOperation(value = "Role增加数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role", value = "职位表实体类", required = true,
                    paramType = "body", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "mids", value = "菜单表id数组", required = true,
                    paramType = "query", dataTypeClass = Integer[].class)
    })
    @PostMapping("/addRole")
    public Result addRole(@RequestBody Role role, Integer[] mids){

        Result result = iRoleService.addRole(role, mids);
        return result;
    }

    @ApiOperation(value = "职位表修改回显数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rid", value = "职位表id", required = true,
                    paramType = "query", dataTypeClass = Integer.class)
    })
    //修改
    @GetMapping("/toUpdate")
    public Result toUpdate(@RequestParam Integer rid){
        Role role = iRoleService.toUpdate(rid);
        return Result.build(ConstantEnum.SUCCESS).setResult(role);
    }


    @ApiOperation(value = "修改职位表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role", value = "职位表实体类", required = true,
                    paramType = "body", dataTypeClass = Role.class),
            @ApiImplicitParam(name = "mids", value = "菜单表id数组", required = true,
                    paramType = "query", dataTypeClass = Integer[].class)
    })
    @PutMapping("updateRole")
    public Result updateRole(@RequestBody Role role, Integer[] mids){
        Result result = iRoleService.updateRole(role, mids);
        return result;
    }

    @ApiOperation(value = "删除职位表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "rid", value = "职位表id", required = true,
                    paramType = "query", dataTypeClass = Integer.class)
    })
    //删除
    @DeleteMapping("/deleteByRid")
    public Result deleteByRid(@RequestParam Integer rid){
        Result result = iRoleService.deleteByRid(rid);
        return result;
    }
}
